package com.alittle.core;

import android.accounts.Account;
import android.app.Application;
import android.text.TextUtils;

import com.alittle.api.ChildChangeable;
import com.alittle.api.child.Child;
import com.alittle.core.db.CllSqlHelper;
import com.android.volley.Request;
import com.android.volley.RequestQueue;

import core.DataRequester;
import core.OptionalParam;
import core.ParamProvider;

import com.alittle.support.support.utils.LessLog;


public abstract class LittleApp extends Application implements ChildChangeable, ParamProvider {

    private CllSqlHelper cllSqlHelper;

    private static LittleApp _littleApp;

//    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
//        @Override
//        public void onReceive(Context context, Intent intent) {
//            if (TextUtils.isEmpty(intent.getAction())) {
//                return;
//            }
//            LessLog.d(this, "接收到广播:" + intent.getAction());
//            switch (intent.getAction()) {
//                case LocationEvent.ACTION_LOCATION_REQUEST:
//                    if (AppUtil.isLocationAvailable(lastBDLocation)) {//如果本地已经有有效的定位信息，直接返回有效的定位信息，但是还是会发起一次定位请求
//                        LocationEvent.notifyLocationChangedSuccess(getApplicationContext(), lastBDLocation);
//                    }
//                    requestLocation();
//                    break;
//                case CoreEvent.ACTION_CITY_LOCATE_REQUEST:
//                    requestCityLocate();
//                    break;
//            }
//        }
//    };

    @Override
    public void onCreate() {
        super.onCreate();
        LessLog.d("LittleApp", "onCreate");

        _littleApp = this;

        init();
//        IntentFilter intentFilter = new IntentFilter(LocationEvent.ACTION_LOCATION_REQUEST);
//        intentFilter.addAction(CoreEvent.ACTION_CITY_LOCATE_REQUEST);
//        ALBaseBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, intentFilter);
    }

    @Override
    public void onTerminate() {
        LessLog.d("LittleApp", "onTerminate");
//        ALBaseBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
        DataRequester.stop();
        if (cllSqlHelper != null) {
            cllSqlHelper.close();
        }

        super.onTerminate();
    }

    /**
     * 自定义网络参数
     */
    protected void init() {

    }

    public static LittleApp getInstance() {
        return _littleApp;
    }

    protected boolean isDebug() {
        return false;
    }


    @Override
    public final OptionalParam getParams() {

        return null;
    }

    @Deprecated
    public CllSqlHelper getCllSqlHelper() {
        if (cllSqlHelper == null) {
            cllSqlHelper = new CllSqlHelper(this);
        }
        return cllSqlHelper;
    }



}
